package com.dingding.queue.queue.consumer;

import java.util.Properties;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.aliyun.openservices.ons.api.Consumer;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.dingding.common.core.config.Constants;
import com.dingding.common.core.config.MessageQueueConfig;
import com.dingding.common.core.config.SystemConfig.TagsEnum;
import com.dingding.queue.queue.consumer.listener.BusinessListener;

/**
 * 
 * @ClassName: BusinessConsumer
 * @Description: 执行业务 队列消费者
 * @author yuHaiQing
 * @date 2016年8月11日 上午11:58:54
 * @since V2.4.0
 * 
 */
@Component("businessConsumer")
public class BusinessConsumer extends AbstractConsumer {

	private Logger log = Logger.getLogger(this.getClass());

	@Resource(name = "businessListener")
	private BusinessListener businessListener;

	@Override
	public void intital() {

		try {
			Properties properties = new Properties();
			properties.put(PropertyKeyConst.ConsumerId, MessageQueueConfig.getMESSAGE_QUEUE_BIZ_CONSUMERID());
			properties.put(PropertyKeyConst.AccessKey, Constants.MESSAGE_QUEUE_ACCESSKEY);
			properties.put(PropertyKeyConst.SecretKey, Constants.MESSAGE_QUEUE_SERECTKEY);
			Consumer consumer = ONSFactory.createConsumer(properties);
			consumer.subscribe(MessageQueueConfig.getMESSAGE_QUEUE_TOPIC(), TagsEnum.BUSINESS.toString(),
					businessListener);
			consumer.start();
		} catch (Exception e) {
			log.error("订阅消息队列出现异常！ BusinessConsumer:intital()", e);
		}
	}

}
